/*

 */

const user = require('../models/user');

var userModel = user.userModel;

//1.add
async function addUser(user) {
    try{
        var user = await userModel.create(user);
        if(user=={}||user==undefined){
            console.log('dao失败')
            return {success:false,msg:'用户保存失败！'}

        }else{
            console.log('dao成功')
            return {success:true,user:user};

        }

    }catch (e) {
        console.log('add user is error,reason:'+e);
        console.log('dao错误');
        return {success:false,msg:e};

    }


}

//2.findByName
async function findByName(name) {
    try{
        var user = await userModel.findOne({name:name});
        if(user==undefined||user=={}){
            return {success:false,msg:'查无此人'}
        }else{
            return {success:true,user:user}
        }
    }catch (e) {
        return {success:false,msg:e}
    }
}

exports.addUser = addUser;
exports.findByName = findByName;